using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TestObsfuscator;

// added by C.Chee
using MySql.Data.MySqlClient; 

namespace WebMenu
{
    public partial class _Default : System.Web.UI.Page
    {
        MySqlConnection myConn;
        MySqlDataReader dataReader;
        String myConnectionString;

        protected void Page_Load(object sender, EventArgs e)
        {
            this.tbxDefaultStatus.Text = "";
            WUC_ToggleButtonA.eventToggle_On +=new EventHandler(WUC_ToggleButtonA_eventToggle_On);
            WUC_ToggleButtonA.eventToggle_Off +=new EventHandler(WUC_ToggleButtonA_eventToggle_Off);
        }

        private void WUC_ToggleButtonA_eventToggle_On(object sender, EventArgs ev)
        {
            tbxDefaultStatus.Text = "User COntrol button is SHOW";
        }
        private void WUC_ToggleButtonA_eventToggle_Off(object sender, EventArgs ev)
        {
            tbxDefaultStatus.Text = "User COntrol button HIDE";
        }


        protected void btnCheckASPnet_Click(object sender, EventArgs e)
        {
            this.tbxDefaultStatus.Text = "ASP.Net is working";
        }

        protected void btnCheckOpenDB_Click(object sender, EventArgs e)
        {
            this.testOpenDB();
        }

        private void testOpenDB()
        {
            try
            { // v4 203.98.74.140
              // v5 203.98.74.146
                string sDBname = "";
                string sDBuser = "";
                string sDBpass = "";
                string sDBIPaddress = "";
                Config config = new Config();
                bool btest = false ;
                config.readConfig(ref sDBname, ref sDBuser, ref sDBpass, ref sDBIPaddress, ref btest);
                myConnectionString = "Database=" + sDBname + ";Data Source=" + sDBIPaddress + ";User Id=" + sDBuser + ";Password=" + sDBpass + "";
                //myConnectionString = "Database=test;Data Source=localhost;User Id=root;Password=mysql";
                myConn = new MySqlConnection(myConnectionString);
                myConn.Open();
                this.tbxDefaultStatus.Text = "DB opened OK\n";
            }
            catch (MySqlException msqlE)
            {
                this.tbxDefaultStatus.Text = this.tbxDefaultStatus.Text + "\n" + msqlE.ToString();
            }
            catch (System.Exception sysE) {
                this.tbxDefaultStatus.Text = this.tbxDefaultStatus.Text + "\n" + sysE.ToString();
            }
        }  // testOpenDB

        private void closeDB() {
            myConn.Close();
            this.tbxDefaultStatus.Text += "DB closed OK";
        }


        protected void btnCheckUsingDB_Click(object sender, EventArgs e)
        {
            string sDBname = "";
            string sDBuser = "";
            string sDBpass = "";
            string sDBIPaddress = "";
            Config config = new Config();
            bool btest = false;
            config.readConfig(ref sDBname, ref sDBuser, ref sDBpass, ref sDBIPaddress, ref btest);
            myConnectionString = "Database=" + sDBname + ";Data Source=" + sDBIPaddress + ";User Id=" + sDBuser + ";Password=" + sDBpass + "";
            myConn = new MySqlConnection(myConnectionString);
            myConn.Open();


            string myInsertQuery = "SELECT  * FROM shop where suburb = 'Randwick'";
            MySqlCommand myCommand = new MySqlCommand(myInsertQuery, myConn);

            MySqlDataAdapter myAdapt = new MySqlDataAdapter(myCommand);
            DataSet ds = new DataSet();
            myAdapt.Fill(ds, "shop");

            dataListShops.DataSource = ds.Tables["shop"];
            //this.DataBind();
            dataListShops.DataBind();
        }

        private void testUsingDB() { 
        
        
        }

        protected void btnCheckObsfus_Click(object sender, EventArgs e)
        {
            int iValue =0 ;
            Obsfusc aObsfusc = new Obsfusc();
            tbxDefaultStatus.Text = "Obsfusc is " + aObsfusc.IVar1.ToString();
        }


    }
}
